package com.boarsoft.boar.soagov.protocol.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.soagov.entity.ProtocolInfo;
import com.boarsoft.boar.soagov.protocol.ProtocolInfoBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;

@Component
@RestController
@RequestMapping("/protocol/info")
public class ProtocolInfoAction {
	@Autowired
	private ProtocolInfoBiz protocolInfoBiz;

	/**
	 * 查询所有协议信息
	 * @return 
	 */
	@RequestMapping("/list.do")
	@Authorized(code = "protocol.info.list")
	public ReplyInfo<Object> list(String projId, String key, String orderBy, int pageNo, int pageSize) {
		PagedResult<ProtocolInfo> pr = protocolInfoBiz.list(projId, key, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(true, pr);
	}

	/**
	 * 保存所有协议信息
	 * @return 
	 */
	@RequestMapping("/save.do")
	@Authorized(code = "protocol.info.save")
	public ReplyInfo<Object> save(ProtocolInfo p) {
		protocolInfoBiz.save(p);
		return ReplyInfo.SUCCESS;
	}
	
	@RequestMapping("/update.do")
	@Authorized(code = "protocol.info.update")
	public ReplyInfo<Object> update(ProtocolInfo o) {
		ProtocolInfo p = protocolInfoBiz.get(o.getId());
		p.setCode(o.getCode());
		p.setMemo(o.getMemo());
		p.setName(o.getName());
		p.setPath(o.getPath());
		p.setVer(o.getVer());
		protocolInfoBiz.update(p);
		return ReplyInfo.SUCCESS;
	}

	/**
	 * 删除所有协议信息
	 * @return 
	 */
	@RequestMapping("/delete.do")
	@Authorized(code = "protocol.info.delete")
	public ReplyInfo<Object> delete(String id) {
		protocolInfoBiz.delete(id);
		return ReplyInfo.SUCCESS;
	}
}